<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class RoomUser extends Model
{
    protected $table = 'room_users';
    
    protected $fillable = [
        'room_id', 'user_id', 'join_time', 'score_change'
    ];
    
    public $timestamps = false;
    
    protected $primaryKey = 'id';
    
    /**
     * 获取用户信息
     */
    public function user()
    {
        return $this->belongsTo(User::class, 'user_id');
    }
    
    /**
     * 获取房间信息
     */
    public function room()
    {
        return $this->belongsTo(Room::class, 'room_id');
    }
    
    /**
     * 更新用户在房间内的积分变化
     */
    public function updateScoreChange($change)
    {
        $this->score_change += $change;
        $this->save();
    }
}